<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2019/9/27 0027
  Time: 上午 11:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
    <title>Title</title>
    <jsp:include page="${pageContext.request.contextPath }/resource_path.jsp" flush="true"/>
</head>
<body class="layui-anim layui-anim-up">
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="">首页</a>
        <a>
          <cite>重庆分公司分摊明细</cite>
        </a>
      </span>
</div>
<div class="x-body">

    <div class="layui-row">
        <form class="layui-form layui-col-md12" onsubmit="return false">

            <div class="layui-input-inline" style="width: 165px">
                <select name="keyword1" id="keyword1">
                    <c:forEach items="${warehouseList}" var="warehouse">
                        <option value="${warehouse.id}">${warehouse.warehouse_name}</option>
                    </c:forEach>
                </select>
            </div>
            <input type="hidden" id="dateTime">

            <div class="layui-input-inline" style="width: 150px">
                <input class="layui-input" id="date3"  style="width: 150px">
            </div>
            <%--<input type="text" name="keyword2" id="keyword2" placeholder="请输入备注" autocomplete="off" class="layui-input">
            <input type="text" name="keyword3" id="keyword3" placeholder="请输入SAP/QAD" autocomplete="off" class="layui-input">
            <input type="text" name="keyword4" id="keyword4" placeholder="请输入中文名称" autocomplete="off" class="layui-input">--%>
            <button class="layui-btn layui-btn-normal" data-type="reload"><i class="layui-icon layui-icon-search"></i>检索</button>
        </form>
    </div>
    <xblock>
        <%--<button class="layui-btn layui-btn-warm" id="add"><i class="layui-icon layui-icon-add-circle-fine"></i>新增</button>--%>
        <button class="layui-btn layui-btn-danger" id="del"><i class="layui-icon layui-icon-delete"></i>批量删除</button>
        <button class="layui-btn layui-btn-danger" id="import"><i class="layui-icon layui-icon-download-circle"></i>导入</button>
       <%-- <button class="layui-btn layui-btn-danger" id="import"><i class="layui-icon layui-icon-download-circle"></i>导入</button>
        <button class="layui-btn layui-btn-danger" id="export"><i class="layui-icon layui-icon-upload"></i>导出</button>
        <button class="layui-btn layui-btn-danger" id="dybq"><i class="layui-icon layui-icon-upload-drag"></i>打印标签</button>--%>
    </xblock>
    <table class="layui-hide" id="tableList" lay-filter="tableList"></table>
</div>



<div id="addDivID" style="display:none">
    <form class="layui-form" id="addFormID" style="margin-top:20px">

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">仓库：</label>
                <div class="layui-inline">
                    <select  name="warehouse">
                        <c:forEach items="${warehouseList}" var="warehouse">
                            <option value="${warehouse.id}">${warehouse.warehouse_name}</option>
                        </c:forEach>
                    </select>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">金额：</label>
                <div class="layui-inline">
                    <input type="text" class="layui-input" name="parameter" style="width: 213px;">
                </div>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <div class="layui-inline">
                <label class="layui-form-label">金额：</label>
                <div class="layui-input-block">
                    <textarea name="detail" placeholder="请输入内容" class="layui-textarea" style="width:320px;height:25px"></textarea>
                </div>
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn" id="subBtn" lay-submit lay-filter="addForm">立即提交</button>
                <button  class="layui-btn layui-btn-primary">取消</button>
            </div>
        </div>

    </form>
</div>
<%--导入模板--%>
<div class="modal fade" id="importDiv" hidden="hidden" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-body">
                <div style="text-align: center; padding: 5px">
                    <a href="${pageContext.request.contextPath }/exceltemplate/share.xls">
                        <img alt="导入人工信息-模板" src="${pageContext.request.contextPath }/images/excel_alt_1.png" style="width: 20px;"/>
                        <span style="font-size: 15px; font-weight:200;color:red">share-模板.xls</span>
                    </a>
                </div>
                <form id="importForm" class="layui-form" enctype="multipart/form-data">
                    <div title="Excel导入操作" style="margin-left: 105px; padding: 5px">

                        <input id="file" name="file" type="file" style="margin-bottom: 20px" accept=".xls,.xlsx"/>
                    </div>
                </form>
                <div align="center">
                    <button class="layui-btn layui-btn-blue" onclick="uploadBtn()">导入</button>
                    &emsp;&emsp;
                    <button class="layui-btn layui-btn-primary" onclick="qx()">取消</button>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        var time = new Date();
        var day = ("0" + time.getDate()).slice(-2);
        var month = ("0" + (time.getMonth() + 1)).slice(-2);
        var today = time.getFullYear() + "-" + (month);
        $('#dateTime').val(today);
    })


    layui.use(['table','layer','upload','form','laydate'], function(){
        var table = layui.table;
        var form=layui.form;
        var laydate = layui.laydate;
        laydate.render({
            elem: '#date1'
        });
        laydate.render({
            elem: '#date2'
        });

        laydate.render({
            elem: '#date3',
            type: 'month',
            value: new Date(),
            done:function(value, date, endDate) {
                $('#dateTime').val(value);
            }
        });

        table.render({
            elem: '#tableList'
            ,id:'contentTable'
            ,url: '/amoeba/getShareList.do'
            ,toolbar: '#toolbar'
            ,cols: [[ //表头
                {type: 'checkbox', fixed: 'left'},
                {ffield:'uid',
                    title:'序号',
                    sort: true,
                    width: 60,
                    type:'numbers',
                    align:'center', totalRowText: '合计'}
                ,{field: 'warehouseName', title: '仓库'}
                ,{field: 'ctime', title: '时间'}
                ,{field: 'detail', title: '明细'}
                ,{field: 'money', title: '金额', totalRow: true}
            ]]
            , page: true
            ,totalRow: true
            ,request: {   //如果无需自定义请求参数，可不加该参数
                pageName: 'page' //页码的参数名称，默认：page
                ,limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            ,response: {   //如果无需自定义数据响应名称，可不加该参数
                countName: 'total' //规定数据总数的字段名称，默认：count
                ,dataName: 'rows' //规定数据列表的字段名称，默认：data
            }
            ,done : function(res, curr, count){
                $('th').css({
                    'background-color': '#009688', 'color': '#fff','font-weight':'bold',
                })
            }
        });

        var $ = layui.jquery, active = {
            reload:function(){

                var dateTime = $('#dateTime').val()

                if (dateTime.length < 4) {
                    var time = new Date();
                    var day = ("0" + time.getDate()).slice(-2);
                    var month = ("0" + (time.getMonth() + 1)).slice(-2);
                    var today = time.getFullYear() + "-" + (month);
                    dateTime = today;
                }

                table.reload('contentTable', {
                    where: {
                        'stockId':$("#keyword1").val(),
                        'date':dateTime
                    }
                });
            },
        }

        $('.layui-col-md12 .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });
        $('.select .layui-btn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        form.on('select(changType)', function(data){
            $("#brand1").hide()
            $("#brand2").hide()
            if (data.value == '租赁') {
                $("#brand1").show()
            }
            if (data.value == '折旧') {
                $("#brand2").show()
            }
        })

        $("#add").click(function(){
            $("#brand1").hide()
            $("#brand2").hide()

            layer.open({
                type: 1 ,				//Page层类型
                area: ['30%', '60%']
                ,title: '新增'
                ,shade: 0.6 			//遮罩透明度
                ,maxmin: true 			//允许全屏最小化
                ,anim: 1 				//0-6的动画形式，-1不开启
                ,content: $('#addDivID')
                ,success: function(){

                    form.render();
                }

            });
        });


        //批量删除
        $("#del").click(function(){
            var rowData = table.checkStatus('contentTable');
            var data = rowData.data;
            var idArr = new Array();
            if(data.length == 0){
                toastrStyle();
                toastr.warning("请至少选择一条记录！");
            } else {
                for(var i=0;i < data.length;i++){
                    idArr[i] = data[i].id;
                }
                $.ajax({
                    type:'post',
                    url:'${pageContext.request.contextPath }/amoeba/delShare.do',
                    data:{"idArr" : idArr},
                    success:function(data){
                        layer.confirm('确定删除吗？', function(){
                            if(data > 0){
                                toastr.success("删除成功！");
                                setTimeout(function(){
                                    location.reload();
                                },1000);
                                setTimeout(function(){
                                    window.location.reload();
                                },2000);
                            }else{
                                toastr.warning("删除失败！");
                                location.reload();
                            }
                        });
                    }
                });
            }
        });
        $("#import").click(function(){
            layer.open({
                type: 1 					//Page层类型
                ,area: ['380px', '200px'] 	//宽  高
                ,title: '导入&nbsp;<span style="color: green">注：请点击红色链接下载模板</span>'
                ,shade: 0.6 				//遮罩透明度
                ,maxmin: true 				//允许全屏最小化
                ,anim: 1 					//0-6的动画形式，-1不开启
                ,content:$('#importDiv')
            });
        });

        /**  data:{itemName:"12",startDate:'2019-09-20'},
         * 通用表单提交(AJAX方式),totalMoney:100,startDate:'2019-09-20',dueDate:'2019-09-20'
         */
        form.on('submit(addForm)', function () {

            $("#subBtn").attr("disabled",true);
            $.ajax({
                type:'post',
                url:'${pageContext.request.contextPath }/otherCost/add.do',
                data:$('#addFormID').serialize(),
                cache:false,
            }).done(
                function(res) {
                    if (res > 0) {
                        toastr.success('新增成功！');
                        setTimeout(function(){
                            location.reload();
                        },1000);
                    }
                }
            ).fail(
                function() {
                    toastr.error('新增失败！');
                    setTimeout(function(){
                        location.reload();
                    },1000);
                }
            )
            return false;
        })


    });
    function uploadBtn() {
        var fileName = $("#file").val();
        var formData = new FormData($("#importForm")[0]);

        $.ajax({
            url: '${pageContext.request.contextPath}/share/uplodeFile.do' ,
            type: 'post',
            data: formData,
            async: false,
            cache: false,
            contentType: false,
            processData: false,
            success: function (data) {
                if (data == 1) {
                    toastr.success("文件导入成功！");
                    setTimeout(function() {//使用setTimeout()方法设定定时2000毫秒
                        location.reload();
                    },1000);
                }else if(data == -1){
                    toastr.warning("导入的数据不符合导入条件！");
                }else{
                    toastr.warning("文件格式异常，文件导入失败！");
                }
            },
            error: function (data) {
                toastr.error("文件格式异常，文件导入失败！");
            }
        });

    }

    toastrStyle()
</script>
</body>

</html>
